package service;

import java.util.List;

import com.jfinal.plugin.activerecord.Db;

import domain.Comment;

public class CommentService {

	public List<Comment> findCommentsByPostid(int postid){
		return Comment.dao.find("SELECT * FROM ta_comment WHERE replyid=? AND replyType = 1",postid);
	}
	
	public List<Comment> findCommentsByCommentid(int commentid){
		return Comment.dao.find("SELECT * FROM ta_comment WHERE replyid=? AND replyType = 2",commentid);
	}
	
	public boolean deleteCommentByCommentid(int commentid){
		return Comment.dao.deleteById(commentid);
	}
	
	public boolean makeComment(int replyid,int replyType,int userid,String time,String content){
		return new Comment().set("replyid", replyid).set("replyType", replyType).set("userid", userid).set("time", time).set("content", content).save();
	}

	public int findCommentOwnerid(int commentid){
		int ownerid = Comment.dao.findById(commentid).getInt("userid");
		return ownerid;
	}
	
}
